<script type="text/javascript"><!--//--><![CDATA[//><!--

  
	var grid_reload = function() {
        $('#datagrid').datagrid('reload', $('#fm_search').serializeObject());
    };

    $(document).ready(function() {

        var kode_kasir_id = '<?php echo $kode_kasir_id ; ?>'

        // Create Datagrid
        $('#datagrid').datagrid({
            url: gs_path + '/' + controller + '/getdata',
            queryParams: $('#fm_search').serializeObject(),
            height: 340,
            pagination: true,
            columns: [[
				{ field : 'ck', checkbox:true, width: 40, align: 'center' },
                { field: 'cabang_nama', title: 'Nama Cabang', width: 200 },
                { field: 'kasir_nama', title: 'Nama Kasir', width: 200  },
                { field: 'kasir_kode', title: 'Kode Kasir', width: 120 },
            ]]
        });

        // Setup Form
        $('#form_master').setupForm([
            { name: 'cabang_id', type: 'text', data: <?php echo json_encode($comboCabang); ?>, size: 'long', maxlength: 30, noempty:true },
            { name: 'kasir_nama', type: 'text', size: 'medium', maxlength: 200, noempty:true },
            { name: 'kasir_kode', type: 'text', size: 'short', maxlength: 255, noempty:true },
        ]);

        // Create Dialog
        $('#dialog_container').dialog({
            closed:true,
            modal:true,
            title: '_',
            width:500,
            height:250,
            buttons:[{
                text:'Save',
                iconCls:'icon-save',
                handler:function(){
                    $('#form_master').submitForm('/'+controller+'/ajax_post', { onComplete : function(){ $('#dialog_container').dialog('close'); $('#datagrid').datagrid('reload'); }} );
                }
            },{
                text:'Close',
                iconCls:'icon-cancel',
                handler:function(){
                    $('#dialog_container').dialog('close');
                }
            }]
        });
        
        
        // Set Action Button
        var buttons = [
                        // ----- >> Add Button
                        { label: 'Add', icon: 'add', onclick: function() {
                          resetError();
                          alert(kode_kasir_id);
                            $('#dialog_container').dialog('open');
                            $('#form_master').data('mode', 'create');
                            $('#form_master').parent().parent().parent().prev().find('.panel-title').html('New Kasir');
                            $('#cabang_nama').readonly(false);
                            $('#cabang_nama, #kasir_nama, #kasir_kode').val('');
                            $('#kode_kasir_id').setval(kode_kasir_id);
                            $('#cabang_nama').focus();
                        }},
                        
                        // ----- >> Edit Button
					    { label: 'Edit', icon: 'edit', onclick: function() {
					        var oSel=$('#datagrid').datagrid('getSelected'); 
                            console.log(oSel);
                            if(oSel==null){ alert('Please select row!'); }
                            else{ 
                                resetError();
                                $('#dialog_container').dialog('open'); 
                                $('#form_master').data('mode', 'edit');
                                $('#form_master').parent().parent().parent().prev().find('.panel-title').html('Edit Kasir');
                                //$('#cabang_nama').readonly();
                                jsonToForm(oSel); $('#kasir_kode').focus();
                                
                            } 
					    }},

					    // ----- >> Delete Button
						{label: 'Delete', icon: 'delete', onclick: function() { 
							var oSel = $('#datagrid').datagrid('getSelected'); 
							if (oSel == null) { 
								$.messager.alert('&nbsp;', gs_msg_row_unselected, 'warning'); 
							} else { 
								deleteData(['kode_kasir_id']);
							} 
						}}];
        setAction(buttons);
		
		
		$('#fm_search').focusFirst();
    });
//--><!]]></script>

    
<div id="tb" style="padding:5px;height:auto">
    <div>
        <form id="fm_search" onsubmit="grid_reload(); return false;">
        	<table class="tb_form" style="margin-bottom:0px">
            <tr>
            	<td width="100">Keyword</td>
                <td><input type="text" id="keyword" name="keyword" class="textfield medium" />
                	<a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="grid_reload(); return false;">Search</a>
			    </td>
            </tr>
            </table>
        </form>
    </div>
</div>
<div id="datagrid" toolbar="#tb"></div>

<div id="dialog_container" style="padding:5px;width:600px;height:600px;">
    <form id="form_master">
        <table class="tb_form" style="display:none;" cellpadding="0" cellspacing="0">
            <tr>
                <td><input id="kode_kasir_id" name="kode_kasir_id" type="hidden" /></td>
            </tr>
            <tr>
                <td class="label">Nama Cabang</td>
                <td><input id="cabang_id" /></td>
            </tr>
            <tr>
                <td class="label">Nama Kasir</td>
                <td><input id="kasir_nama" /></td>
            </tr>
            <tr>
                <td class="label">Kode Kasir</td>
                <td><input id="kasir_kode" /></td>
            </tr>
        </table>
    </form>
</div>
